package com.smart.translator.data.repository;

import com.smart.translator.data.api.RetrofitClient;
import com.smart.translator.data.api.TranslationService;
import com.smart.translator.data.model.TranslationResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TranslationRepository {
    private final TranslationService translationService;

    public TranslationRepository() {
        this.translationService = RetrofitClient.getInstance().create(TranslationService.class);
    }

    public String translate(String text, String sourceLanguage, String targetLanguage) throws Exception {
        Call<TranslationResponse> call = translationService.translate(text, sourceLanguage, targetLanguage);
        Response<TranslationResponse> response = call.execute();
        
        if (response.isSuccessful() && response.body() != null) {
            return response.body().getTranslatedText();
        } else {
            throw new Exception("翻译失败: " + (response.errorBody() != null ? response.errorBody().string() : "未知错误"));
        }
    }
} 